/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author vimi Administrator
 */
import model.*;

import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Category;
import org.apache.log4j.FileAppender;
import org.apache.log4j.WriterAppender;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.PropertyConfigurator;

import org.apache.log4j.Level;

import org.apache.log4j.SimpleLayout;



import java.util.Properties;
import java.io.IOException;
import java.io.FileOutputStream;

import java.util.List;
import java.util.ArrayList;

public class SolWriter {
    static final Logger logger = Logger.getLogger(SolWriter.class.getName());

    //public Logger logger = Logger.getLogger(SolWriter.class.getName());

    static final String LOG_PROPERTIES_FILE = "config/SolLog4J.properties";
    
    public List<Course> Courses;
    public List<Room> Rooms;
    public int DayNum;
    public int Periods_per_Day;

    public int [][] Solution;

    public SolWriter(String filename)
    {
        PatternLayout layout = new PatternLayout("%m");
        

          FileAppender appender = null;
          try {
             appender = new FileAppender(layout,filename,false);
          } catch(Exception e) {}

        logger.addAppender(appender);
        logger.setLevel((Level) Level.DEBUG);




        //initializeLogger();
        
    }

    private void initializeLogger()
    {
        Properties logProperties = new Properties();

        try
        {
          // load our log4j properties / configuration file
          //logger.addAppender(outAppender);
          logProperties.load(SolWriter.class.getResourceAsStream(LOG_PROPERTIES_FILE));
          PropertyConfigurator.configure(logProperties);
          //logger.addAppender(appender);
          
        }
        catch(IOException e)
        {
          throw new RuntimeException("Unable to load logging property " + LOG_PROPERTIES_FILE);
        }
    }
    

    public void writeSolDown()
    {
        for (int i=0;i<Solution.length;i++)
        {
            for (int j=0;j<Solution[i].length;j++)
            {

                if (Solution[i][j]>-1)
                {
                    int r = Solution[i][j];
                    int day = Math.round(j/Periods_per_Day);
                    int period = j-Math.round(j/Periods_per_Day)*Periods_per_Day;

                    logger.info(Courses.get(i).getCourseID()+" "+
                                Rooms.get(r).getId()+" "+
                                day+" "+
                                period+"\n"
                                );

                }
            }
            
        }
        
    }



}
